class Solution(object):
    def minOperations(self, boxes):
        n = len(boxes)
        ans = [0] * n
        prefix = [0] * n
        prefix[0] = int(boxes[0] == '1')
        for i in range(1, n):
            prefix[i] = prefix[i - 1] + int(boxes[i] == '1')
        for i in range(1, n):
            ans[0] += int(boxes[i] == '1') * i
        for i in range(1, n):
            ans[i] = ans[i - 1] + prefix[i - 1] - (prefix[-1] - prefix[i - 1])
        return ans


